package wy2;

import java.util.Scanner;

public class Main2 {
    private static int max=0;
    private static int[] values;
    private static boolean[] visited;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] strs=sc.nextLine().split(" ");
        int len=strs.length;
        values=new int[len];
        visited=new boolean[len];
        for (int i = 0; i < len; i++) {
            values[i]=Integer.valueOf(strs[i]);
        }
        cal(0,0);
        System.out.println(max);

    }
    private static void cal(int index,int cur){
        if(index==visited.length){
            max=Math.max(cur,max);
            return;
        }
        for (int i = 0; i < visited.length; i++) {
            if(!visited[i] ){
                visited[i]=true;
                if(isMax(i)) {
                    visited[i]=false;
                    continue;
                }
                int left=findL(i);
                int right=findR(i);
                int temp=values[i]*left*right;
                cur+=temp;
                cal(index+1,cur);
                cur-=temp;
                visited[i]=false;
            }
        }

    }
    private static  int findL(int index){
        for (int i = index-1; i >= 0; i--) {
            if(!visited[i]) return values[i];
        }
        return 1;
    }
    private static  int findR(int index){
        for (int i = index+1; i < values.length; i++) {
            if(!visited[i]) return values[i];
        }
        return 1;
    }
    private static boolean isMax(int index){
        for (int i = 0; i < values.length; i++) {
            if(i==index) continue;
            if(!visited[i]){
                if(values[i]>=values[index]) return false;
            }
        }
        return  false;

    }
}
